package com.flyoil.petromp.utils.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyoil.petromp.R;


/**
 * Created by songzhiiyn on 2017/8/23.
 * 自定义提示信息的弹框工具类
 */

public class DialogHintUtil {
    private static Dialog dialog;
    private static TextView tv_title;
    private static TextView tv_content;
    private static TextView tv_cancel;
    private static TextView tv_confirm;

    /**
     * 显示提示信息的弹框
     */
    public static void show_hint_message_diolog(final Context context) {
        if (dialog != null) {
            dialog.dismiss();
        }
        LayoutInflater inflaterDl = LayoutInflater.from(context);
        LinearLayout layout = (LinearLayout) inflaterDl.inflate(R.layout.dialog_hint_util_layout, null);
        dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.getWindow().setContentView(layout);
        dialog.setCancelable(false);
        tv_title = (TextView) layout.findViewById(R.id.tv_dialog_hint_message_title);
        tv_content = (TextView) layout.findViewById(R.id.tv_dialog_hint_message_content);
        tv_cancel = (TextView) layout.findViewById(R.id.tv_dialog_hint_message_cancle);
        tv_confirm = (TextView) layout.findViewById(R.id.tv_dialog_hint_message_confirm);
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    /**
     * 给确定按钮设置点击事件
     *
     * @param onclicklistener
     */
    public static void set_confirm_onclicklistener(View.OnClickListener onclicklistener) {
        if (tv_confirm != null) {
            tv_confirm.setOnClickListener(onclicklistener);
        }
    }

    /**
     * 给取消按钮设置点击事件
     *
     * @param onclicklistener
     */
    public static void set_cancel_onclicklistener(View.OnClickListener onclicklistener) {
        if (tv_cancel != null) {
            tv_cancel.setOnClickListener(onclicklistener);
        }
    }

    /**
     * 关闭dialog弹框
     */
    public static void dismiss_dialog() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    /**
     * 设置dialog的标题
     *
     * @param title
     */
    public static void set_dialog_title(String title) {
        if (tv_title != null) {
            if (title != null && title.length() > 0) {
                tv_title.setText(title);
                tv_title.setVisibility(View.VISIBLE);
            } else {
                tv_title.setVisibility(View.GONE);
            }

        }
    }

    /**
     * 设置dialog的内容
     *
     * @param content
     */
    public static void set_dialog_content(String content) {
        if (tv_content != null) {
            if (content != null && content.length() > 0) {
                tv_content.setText(content);
                tv_content.setVisibility(View.VISIBLE);
            } else {
                tv_content.setVisibility(View.GONE);
            }

        }
    }

    /**
     * 设置取消按钮的内容
     *
     * @param cancle
     */
    public static void set_dialog_cancle(String cancle) {
        if (tv_cancel != null) {
            if (cancle != null && cancle.length() > 0) {
                tv_cancel.setText(cancle);
                tv_cancel.setVisibility(View.VISIBLE);
            } else {
                tv_cancel.setVisibility(View.GONE);
            }

        }
    }

    /**
     * 设置确定按钮的内容
     *
     * @param content
     */
    public static void set_dialog_confirm(String content) {
        if (tv_confirm != null) {
            if (content != null && content.length() > 0) {
                tv_confirm.setText(content);
                tv_confirm.setVisibility(View.VISIBLE);
            } else {
                tv_confirm.setVisibility(View.GONE);
            }

        }
    }


}
